package listbyorder.access101_200.test115;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/21 10:13
 */
public class Solution4 {

    // 正向动态规划
    public int numDistinct(String s, String t) {
        int lens = s.length();
        int lent = t.length();
        int[][] dp = new int[lens + 1][lent + 1];
        // 当t为空串时，结果为1
        for (int i = 0; i <= lens; i++) {
            dp[i][0] = 1;
        }
        for (int i = 1; i <= lens; i++) {
            for (int j = 1; j <= i && j <= lent; j++) {
                if (s.charAt(i - 1) == t.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        return dp[lens][lent];
    }
}
